﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BarcodeDelay.view
{
    public partial class FrmSiteSetting : Form
    {
        public FrmSiteSetting()
        {
            InitializeComponent();
        }


        private void btnSetting_Click(object sender, EventArgs e)
        {
            if(!this.rbIntercept.Checked&&!this.rbCustomerNotExist.Checked&&!this.rbReturn.Checked)
            {
                MessageBox.Show("请选择一个登记拦截类型");
                return;
            }
            string strType = "";
            if(this.rbIntercept.Checked)
            {
                strType = "intercept";
            }
            else if (this.rbReturn.Checked)
            {
                strType = "return";
            }
            else if (this.rbCustomerNotExist.Checked)
            {
                strType = "customer";
            }
            StoParams.Instance.probleTypeSubject = strType;
            this.Close();
            /*if(tbSiteName.Text.Trim().Length>1)
            {
                writeTbFile(tbSiteName.Text.Trim());

                this.Close();
            }
            else
            {
                MessageBox.Show("网点名称不能为空");
            }*/

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void writeTbFile(string strSiteName)
        {
            try
            {
                string delFile = System.Environment.CurrentDirectory + "\\" + StoParams.Instance.siteTxtPath;
                File.Delete(delFile);
                FileStream bFile = new FileStream(delFile, FileMode.Create);
                StreamWriter swb = null;
                if (swb == null)
                {
                    swb = new StreamWriter(bFile);
                }
                StoParams.Instance.register_site = strSiteName;
                swb.WriteLine("regsite "+strSiteName);
                swb.Close();

            }
            catch (Exception ex)
            {

            }
        }

        private void FrmSiteName_Load(object sender, EventArgs e)
        {
            
            if(StoParams.Instance.probleTypeSubject== "intercept")
            {
                this.rbIntercept.Checked = true;
            }
            else if (StoParams.Instance.probleTypeSubject == "return")
            {
                this.rbReturn.Checked = true;
            }
            if (StoParams.Instance.probleTypeSubject == "customer")
            {
                this.rbCustomerNotExist.Checked = true;
            }
        }
    }
}
